@extends('layouts.buz.layout', ['header_active' => 'member'])

@section('sidebar')
    @include('layouts.buz.sidebar.member', ['active' => 'remit'])
@endsection()
@section('title')
    个人中心 - 结算信息
@endsection()
@section('content')
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="panel-title">
                结算银行卡
                <a atype="button" class="btn btn-default right" href="/member/remit/create">新增</a>
            </h4>
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-sm-6 col-md-6 lineH28">
                    <div class="form-group">
                        <label for="" class="col-sm-3">银行类型</label>
                        <div class="col-sm-9 col-md-9">
                            <select class="form-control" name="bankType" id="bankType">
                                <option value="-">全部</option>
                                @foreach(\App\Lib\BankMap::getMap() as $code => $map)
                                    <option value="{{$code}}">{{$map}}</option>
                                @endforeach
                            </select>
                        </div>

                    </div>
                </div>
                <div class="col-sm-3 lineH28">
                    <div class="form-group">
                        <div class="col-sm-3 padd">
                            <button type="button" class="btn btn-primary" id="search">查询</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="historyList" id="billList">
                <table class="table table-striped table-bordered" id="table">
                </table>
            </div>
        </div>
    </div>
    @endsection()
@section('bottom_js')
    <script>
        $(function () {
            $('#table').bootstrapTable({
                url: '/api/profile/remit',
                queryParamsType: '',              //默认值为 'limit' ,在默认情况下 传给服务端的参数为：offset,limit,sort
                queryParams: queryParams,
                method: "get",
                pagination: true,
                pageNumber: 1,
                pageSize: 20,
                pageList: [10, 20, 50, 100],
                sidePagination: "server",         //分页方式：client客户端分页，server服务端分页（*）
                striped: true,                    //是否显示行间隔色
                cache: false,
                uniqueId: "id",               //每一行的唯一标识，一般为主键列
                height:700,
                paginationPreText: "上一页",
                paginationNextText: "下一页",
                onLoadSuccess: function(data){  //加载成功时执行
                    //这个地方可以放每页的统计信息
                },
                responseHandler: function(res) {
                    if(filterAjaxData(res)){
                        return {
                            "total": res.data.total,//总页数
                            "rows": res.data.data   //数据
                        };
                    }else {
                        $("#loginModel").modal("toggle");
                    }

                },
                columns: [
                    { title: 'ID', field: 'id',visible: false, width: 50, align: "center"},
                    { title: '银行类型', field: 'bankName'},
                    { title: '开户性质类型', field: 'classify', formatter: function (value, row, index) {
                            if (value == '1') return '企业';
                            else return '个人';
                        }},
                    { title: '开户人姓名', field: 'username' },
                    { title: '开户行账号', field: 'account'},
                    { title: '开户行省级', field: 'city.province'},
                    { title: '开户行市级', field: 'city.city'},
                    { title: '开户支行名称', field: 'branch' },
                    { title: '默认', field: 'is_default', formatter: function (value, row, index) {
                            if (value == '1') return '是';
                            else return '否';
                        }},
                    { title: '添加时间', field: 'created_at' },
                    { title: '操作', formatter: function (value, row, index) {
                            var str="";
                            if (row.is_default != "1") {
                                str += '<button type="button" class="btn btn-info" onclick="setDefault('+row.id+')" >设为默认</button>';
                            }
                            str +='<a type="button" class="btn btn-info detailList" href="/member/remit/'+row.id+'">更改</a>';
                            str +='<button type="button" class="btn btn-danger" onclick="delRemit('+row.id+')" >删除</button>';
                            return str;
                    } }
                ],
            });
        })
        //查询条件
        function queryParams(params) {
            return {
                pageSize: params.pageSize,
                page: params.pageNumber,
                billType: $("#bankType").val(),
            };
        }

        $("#billList").on("click",".pagination li a",function () {
            var _url = $(this).attr("data-url");
            if(_url){
                $.ajax({
                    url: _url,
                    type: 'get',
                    success:function(data){
                        if(filterAjaxData(data)){
                            console.log(data);

                            var html = template('list', data.data);
                            document.getElementById('billList').innerHTML = html;
                        }
                    }
                });
            }else{
                showMsg("没有啦")
            }
        });

        //查询
        $("#search").click(function(){
            $('#table').bootstrapTable('refreshOptions', { pageNumber: 1 });
        });

        //补发
        function delRemit(id) {
            console.log(id);
            $.ajax({
                url: "/api/profile/remit/"+id,
                type: 'delete',
                success:function(data){
                    if(filterAjaxData(data)){
                        showMsg('删除成功');
                        window.location.reload();
                    }
                }
            });
        }

        //补发
        function setDefault(id) {
            $.ajax({
                url: "/api/profile/remit/"+id+"/setDefault",
                type: 'post',
                success:function(data){
                    if(filterAjaxData(data)){
                        showMsg('设置成功');
                        window.location.reload();
                    }
                }
            });
        }

    </script>
@endsection()
